﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace DXApplication1月报表
{
    public partial class XtraForm用户管理 : DevExpress.XtraEditors.XtraForm
    {
        public XtraForm用户管理()
        {
            InitializeComponent();
        }

        private void simpleButton增加_Click(object sender, EventArgs e)
        {
            Form form = new XtraForm增加用户();
            form.ShowDialog();
            查询();
        }

        private void XtraForm用户管理_Load(object sender, EventArgs e)
        {
            查询();
        }

        private void 查询()
        {
            //查出所有用户
            string sql = "select * from z_用户名密码";
            DataTable dt = SqlHelper.SqlHelper.ExecuteDataset(sql).Tables[0];
            gridControl1.DataSource = dt;
            gridView1.BestFitColumns();

        }

        private void repositoryItemButtonEdit删除_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            //询问是否确定删除
            if (MessageBox.Show("确定删除吗？", "提示", MessageBoxButtons.OKCancel) != DialogResult.OK)
            {
                return;
            }
            //获取当前行id
            int id = Convert.ToInt32(gridView1.GetFocusedRowCellValue("id"));
            //删除
            string sql = "delete from z_用户名密码 where id=" + id;
            int r = SqlHelper.SqlHelper.ExecuteNonQuery(sql);
            if (r > 0)
            {
                MessageBox.Show("删除成功");
                查询();
            }
        }
    }
}